﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.IO;

namespace VBGBuilder
{
    static class Program
    {
      private static String QUIT = "QUIT";
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
          DLG dlg = getDLG();
          if (dlg == null) {
            return;
          }
          SVNFactory svn = new SVNFactory(new FileInfo("\\\\epicsys.com\\files\\Release\\Release Tools\\Utilities\\SVNSupport\\bin\\svn.exe"));
          dlg.svn = svn;

          String vbgFileName;
          do {
            vbgFileName = getVBG();
            if (vbgFileName != "") {
              dlg.getVBFile(vbgFileName );
            }
          } while (vbgFileName != "");
        }

        private static DLG getDLG() {
          String input ="";
          DLG dlg=null;
          do {
            Console.WriteLine("DLG branch(? for help): ");
            input=Console.ReadLine().ToUpper ();
            if ("QUIT"==input ) {
              return null;
            }
            if ("?"==input || input==null ) {
              Console.WriteLine("input dlg branch, supports I76 and current version.");
              Console.WriteLine("Example: I7652545 or 837839-3");
              Console.WriteLine("quit to quit");
              Console.WriteLine("? for help");
            }
            if (input != null) {
              String dlgPath = "";
              String svnURL = "http://einstein/svn/prd/branches/dlg/"+input;

              if (input.StartsWith("I76")) {
                dlgPath = "C:\\EpicSource\\7.6\\DLG-" + input; 
              }
              else {
                dlgPath = "C:\\EpicSource\\7.7\\DLG-" + input;
              }
              DirectoryInfo root = getDlgFolder(dlgPath);
              if (root!=null) {
                dlg = new DLG(root);
                dlg.svnURL = svnURL;
              }
            }
            
          } while (dlg==null);
          return dlg;
        }

        private static DirectoryInfo  getDlgFolder(String path) {
          DirectoryInfo folder = null;  
          try {
              folder = new DirectoryInfo (path);
              if (!folder.Exists) {
                folder.Create();
              }
            }
            catch (Exception e) {
              Console.WriteLine(e.ToString());
              folder  = null;
            }
          return folder;
        }

        private static String getVBG() {
          String input = "";
          do {
            Console.WriteLine("VBG file (QUIT to quit): ");
            input = Console.ReadLine();
            if (input == QUIT) {
              return "";
            }
          } while (input == null);
          return input;
        }

    }
}
